package com.xrit.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.constant.MessageConstant;
import com.xrit.sunnyday.entity.PageResult;
import com.xrit.sunnyday.entity.QueryPageBean;
import com.xrit.sunnyday.entity.Result;
import com.xrit.sunnyday.pojo.Role;
import com.xrit.sunnyday.service.RoleService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 角色管理
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Reference
    private RoleService roleService;

/*    *//**
     * 角色条件分页查询
     * @param queryPageBean
     * @return
     *//*
    @PostMapping("/pagination")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        //调用服务分页查询
        PageResult pageResult = roleService.findPage(queryPageBean);
        return new Result(true, MessageConstant.QUERY_ROLE_SUCCESS,pageResult);
    }*/
    /**
     * 按条件分页查询
     */
    @PostMapping("/pagination")
    public Result pagination(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = roleService.pagination(queryPageBean);
        Result result = new Result(true, MessageConstant.QUERY_ROLE_SUCCESS,pageResult);
        return result;
    }
    /**
     * 添加角色与权限
     * @param role
     * @return
     */
    @PostMapping("/RoleAdd")
    public Result RoleAdd(@RequestBody Role role , Integer[] permissionIds, Integer[] menus) {
        roleService.RoleAdd(role,permissionIds,menus);
        Result result = new Result(true,MessageConstant.ADD_ROLE_SUCCESS);
        return result;
    }

    /**
     * 查询回显角色信息权限以及菜单
     * @param id
     * @return
     */
    @PostMapping("/QueryById4Edit")
    public Result QueryById4Edit(Integer id) {
        Map<String, Object> stringObjectMap = roleService.QueryById4Edit(id);
        Result result = new Result(true, "查询成功！",stringObjectMap);
        return result;
    }

    /**
     * 删除角色信息
     * @param id
     * @return
     */
    @PostMapping("/RoleDelete")
    public Result RoleDelete(@PathVariable Integer id) {
        roleService.RoleDelete(id);
        Result result = new Result(true, MessageConstant.DELETE_ROLE_SUCCESS);
        return result;
    }

    /**
     * 根据角色ID修改角色信息
     * @param
     * @return
     */
    @PostMapping("/RoleUpdate")
    public Result RoleUpdate(@RequestBody Role role ,Integer[] permissionIds, Integer[] menus) {
        roleService.RoleUpdate(role,permissionIds,menus);
        Result result = new Result(true, MessageConstant.EDIT_ROLE_SUCCESS);
        return result;
    }
}
